// index.js
// 获取应用实例
const app = getApp()
import {request} from "../../request/index.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 轮播图数组
    swiperList: [],
    //导航数组
    navList: [],
    //楼层数组
    floorList: [],
    urls: []
  },
  urls: [],
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   method: 'GET',
    //   success: (result) => {
    //     //运用promise优化回调地狱
    //    this.setData({
    //      //拿取轮播图数组
    //      swiperList:result.data.message
    //    });
    //   }
    // })
    //轮播图
    this.getSwiperList();
    this.getNavList();
    this.getFloorList();
  },
  getSwiperList() {
    request({
      url: '/home/swiperdata'
    }).then(result => {
      this.setData({
        //拿取轮播图数组
        swiperList:result.data.message
      });
    });
  },
  getNavList() {
    request({
      url: '/home/catitems'
    }).then(result => {
      this.setData({
        //拿取轮播图数组
        navList:result.data.message
      });
    });
  },
  getFloorList() {
    request({
      url: '/home/floordata'
    }).then(result => {
      this.setData({
        floorList:result.data.message
      });
      //拿取超链接
      this.getNavGo();
    });
  },
  //超链接数组
  getNavGo() {
    let urls = [],floorList = this.data.floorList;
    floorList.forEach(v => {
      //拿出列表数组
      urls.push(v.product_list);
    });
    // console.log(this.data.floorList);
    urls.forEach((v, i) => {
      //列表数组的数组循环一次
      v.forEach((v, j)=> {
        // 再把列表数组的数组的数组循环一次并修改其的值
        urls[i][j].navigator_url = "/pages/goods_list/goods_list?" + v.navigator_url.split("?")[1];
      });
    });
    floorList.forEach((v, i ) => {
      v.product_list = urls[i];
    });
    // console.log(floorList);
    this.setData({
      floorList
    });
  }
})